#!/usr/bin/env python
# -*- coding: utf-8 -*-
#  response.py
#  description

#  Created by zhouzongli633 on 2020/5/21 2:24 下午.
#  Copyright ©Intellectus All rights reserved.

import json

from django.http import HttpResponse

_err_msg = {
    0: 'Success',
    -1: 'Server error.Please try again later.',
    1000: "Sorry, you don't have permission to access this resource",
    1001: "Sorry, This service does not have this user",
    1002: "Sorry, you don't have access to this hospital",
    1003: "This search is invalid",
    1004: "Illegal user does not have access rights",
    1005: "Sorry, you don't have this operation in this hospital",
    1006: "Sorry, the tag already exist",
    1007: "request to babysense service failed",
    2001: "Sorry, the parent already exist",
    2002: "Sorry, the baby already exist",
    2003: "Sorry, the database not has this user data",
    2004: "Sorry, the hospital not has this baby data",
    2005: "The database does not have this record.",
    3001: 'http method error',
    3002: 'token check failure',
    3003: 'check your email and password',
    3004: 'param missing',
    3005: 'body arguments missing',
    4001: 'record not found',
    4002: 'check your commit information',
    4003: 'Already existed category name',
    4004: 'Please write modify title',
    4005: 'Please send the parameter id',
    4006: 'Our web only support max_level is 5',
    4007: 'This hospital already exist',
    4008: 'please select a content in relate content but not a category',
    4009: 'please select a hospital or a category firstly.',
    4010: 'please select a correct language.',
    4011: 'please check your selected source.',
    5001: 'Please check your email.',
    5002: 'You have already signed up! Please login to continue.',
    5003: 'family member already present.',
    5004: 'user does not exist.',
    5005: 'invitation not created',
    5006: 'Invalid invitation code',
    5007: 'Invalid invitee name or email or code. Please check your email.',
    5008: 'Your current password does not match our records',
    5009: 'Cannot change password, your new password should be minimum of 8 characters',

}


def resp(code, data={}, ruby=False):
    if not ruby:
        result = {'error_code': code}
        if code in _err_msg:
            result['message'] = _err_msg[code]
            result['data'] = data
        else:
            result['message'] = "request except."
            result['data'] = data

        respond = HttpResponse(json.dumps(result), content_type="application/json")
        return respond

    else:
        respond = HttpResponse(json.dumps(data), content_type="application/json")
        return respond
